<?php
/*
 * @开发工具: JetBrains PhpStorm.
 * @文件名：SystemController.class.php
 * @类功能: 系统设置
 * @开发者: cxl
 * @开发时间： 15-10-22
 * @版本：version 1.0
 */
namespace app\admin\controller;

use app\common\cache\bank\IBankCache;
use app\common\cache\bank\IBankTypeCache;
use app\common\cache\common\INavigationCache;
use app\common\cache\common\ISpecialCache;
use app\common\enum\AppType;
use app\common\widget\ListTree;
use app\common\cache\admin\IAdminCache;
use app\common\cache\admin\IAdminRoleCache;
use app\common\cache\common\IAdCache;
use app\common\cache\common\IAdLocationCache;
use app\common\cache\common\IAnnouncementCache;
use app\common\cache\common\IAreaCache;
use app\common\cache\common\IConfigCache;
use app\common\cache\common\IProtocolCache;
use app\common\cache\common\IStartPhotoCache;
use app\common\controller\AdminBaseController;
use app\common\enum\AdminSuper;
use app\common\enum\IsDelete;
use app\common\enum\SuggestType;
use app\common\ext\IConfig;
use app\common\ext\IDb;
use app\common\ext\IRedis;
use app\common\ext\IRequest;
use think\Cache;

class System extends AdminBaseController {
    /**
     * @功能：清除缓存
     * @开发者：cxl
     */
    public function clear_cache_all(){
        //清除redis缓存
        IRedis::flushDB();

        //清除文件缓存
        rm_directory(RUNTIME_PATH);

        //创建目录
        @mkdir(RUNTIME_PATH."temp",0755,true);
        @mkdir(RUNTIME_PATH."cache",0755,true);
        @mkdir(RUNTIME_PATH."data",0755,true);
        @mkdir(RUNTIME_PATH."log",0755,true);

        //画面跳转
        $this->success("操作成功！");
    }

    /**
     * @功能：配置项列表
     * @开发者：cxl
     */
    public function config_list(){
        //实例化对象
        $config_list = IConfigCache::getList();

        //模版渲染
        $this->assign("config_list",$config_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：配置项编辑
     * @开发者：cxl
     */
    public function config_edit(){
        //接收参数
        $config_code = IRequest::get('config_code',IRequest::NOT_EMPTY,"配置项编码不能为空！");

        //修改保存
        $config_info = IConfigCache::getInfo($config_code);

        //模版渲染
        $this->assign("config_code",$config_code);
        $this->assign("config_info",$config_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：配置项保存
     * 开发者：cxl
     */
    public function config_submit(){
        //接收参数
        $config_code = IRequest::get("config_code",IRequest::NOT_EMPTY,"请输入配置项编码！");
        $val = IRequest::get("val",IRequest::NOT_EMPTY,"请输入配置项值！");
        $remark = IRequest::get("remark");

        //判断是否设置首页数量
        if($config_code == "HomeUserReceive"){
            $HomeUserNum = IConfig::getValue("HomeUserNum");
            $HomeUserNum = intval($HomeUserNum);
            $val = intval($val);
            if($HomeUserNum <= $val){
                error("领取客户数量必须小于累计客户数量！");
            }
        }

        //判断是否设置首页数量
        if($config_code == "HomeUserNum"){
            $HomeUserReceive = IConfig::getValue("HomeUserReceive");
            $HomeUserReceive = intval($HomeUserReceive);
            $val = intval($val);
            if($HomeUserReceive >= $val){
                error("领取客户数量必须小于累计客户数量！");
            }
        }

        //修改保存
        $com_config_where['config_code'] = $config_code;
        $com_config_data['val']= $val;
        $com_config_data['remark']= $remark;
        $com_config_data['update_admin']= get_login_admin_id();
        $com_config_data['update_time']= get_date_time();
        $config_upd = IDb::getInstance("com_config")->setDbWhere($com_config_where)->setDbData($com_config_data)->upd();
        if($config_upd === false){
            error("修改配置项信息失败！");
        }

        //清除缓存
        IConfigCache::deleteInfo($config_code);
        IConfigCache::deleteList();

        //画面跳转
        $this->redirect("config_list");
    }

    /**
     * @功能：配置项详情
     * @开发者：cxl
     */
    public function config_info(){
        //接收参数
        $config_code = IRequest::get('config_code',IRequest::NOT_EMPTY,"配置项编码不能为空！");

        //修改保存
        $config_info = IConfigCache::getInfo($config_code);;

        //设置layout
        $this->layout("layout_empty");

        //模版渲染
        $this->assign("config_info",$config_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：管理员角色列表
     * @开发者：cxl
     */
    public function role_list(){
        //接收参数
        $role_name = IRequest::get('role_name');
        $admin_super = IRequest::get('admin_super');

        //查询条件
        $admin_role_where = null;
        if(!empty($role_name)) $admin_role_where["role_name"] = array("like","%{$role_name}%");
        if(!empty($admin_super)) $admin_role_where["admin_super"] = array("eq",$admin_super);

        //取得管理员角色列表
        $admin_role_list = IDb::getInstance("admin_role")->setDbWhere($admin_role_where)->pag();

        //模板渲染
        $this->assign('role_name',$role_name);
        $this->assign('admin_super',$admin_super);
        $this->assign('role_list',$admin_role_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加管理员角色
     * @开发者：cxl
     */
    public function role_add(){
        //取得管理员类型
        $admin_super = get_login_admin_super();
        if($admin_super != AdminSuper::Super){
            error("只有超级管理员才有权限！");
        }

        //模板渲染
        $this->assign('admin_super',$admin_super);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑管理员角色
     * @开发者：cxl
     */
    public function role_edit(){
        //接收参数
        $role_id = IRequest::get('role_id',IRequest::NOT_EMPTY,"管理员角色编号不能为空！");

        //取得管理员类型
        $admin_super = get_login_admin_super();
        if($admin_super != AdminSuper::Super){
            error("只有超级管理员才有权限！");
        }

        //取得管理员角色数据
        $admin_role_info = IAdminRoleCache::getInfo($role_id);
        if(empty($admin_role_info['admin_role_id'])){
            error("管理员角色不存在！");
        }

        //模板渲染
        $this->assign('admin_super',$admin_super);
        $this->assign('role_id',$role_id);
        $this->assign('role_info',$admin_role_info);

        //渲染模板输出
        return view('role_edit');
    }

    /**
     * @功能：删除管理员角色
     * @开发者：cxl
     */
    public function role_del(){

        //接收参数
        $role_id = IRequest::get("role_id",IRequest::NOT_EMPTY,"管理员角色编号不能为空！");

        //判断是否为超级管理员
        $admin_super = get_login_admin_super();
        if($admin_super != AdminSuper::Super){
            error("只有超级管理员才有权限！");
        }

        //取得管理员角色数据
        $admin_role_info = IAdminRoleCache::getInfo($role_id);
        if(empty($admin_role_info)){
            error("管理员角色不存在！");
        }

        //取得管理员角色使用信息
        $admin_where['admin_role_id'] = $role_id;
        $admin_info = IDb::getInstance("admin")->setDbWhere($admin_where)->con();

        //判断管理员角色是否已经被使用了
        if(empty($admin_info)){
            //删除管理员角色
            $admin_role_where['admin_role_id'] = $role_id;

            IDb::dbStartTrans();

            $admin_role_menu_del = IDb::getInstance("admin_role_menu")->setDbWhere($admin_role_where)->del();
            if ($admin_role_menu_del === false){
                IDb::dbRollback();
                error("删除管理员角色失败，请联系管理员！");
            }

            $admin_role_del = IDb::getInstance("admin_role")->setDbWhere($admin_role_where)->del();
            if($admin_role_del === false){
                IDb::dbRollback();
                error("删除管理员角色失败，请联系管理员！");
            }

            IDb::dbCommit();

        }else{
            error("管理员角色已经被{$admin_info}个管理员使用了，不能删除！");
        }

        //删除缓存
        IAdminRoleCache::deleteInfo($role_id);

        //画面跳转
        $this->success('操作成功！',Url("role_list"));
    }

    /**
     * @功能：管理员角色保存
     * 开发者：cxl
     */
    public function role_submit(){
        //接收参数
        $role_id = IRequest::get("role_id");
        $role_name = IRequest::get("role_name",IRequest::NOT_EMPTY,"请输入管理员角色名称！");
        $admin_super = IRequest::get("admin_super");
        $remark = IRequest::get("remark");

        //取得管理员类型
        $login_admin_super = get_login_admin_super();
        if($login_admin_super == AdminSuper::Ordinary){
            error("只有超级管理员才有权限！");
        }

        //判断管理员角色是否存在
        $find_where['role_name'] = $role_name;
        if(!empty($role_id)){
            $find_where['admin_role_id'] = ['neq',$role_id];
        }
        $admin_role_info=IDb::getInstance("admin_role")->setDbWhere($find_where)->row();
        if(!empty($admin_role_info)){
            error('管理员角色名已经存在');
        }

        //保存信息
        if(empty($role_id)){
            //新增保存
            $admin_role_data['role_name'] = $role_name;
            $admin_role_data['admin_super'] = $admin_super;
            $admin_role_data['remark'] = $remark;
            $admin_role_data['create_admin'] = get_login_admin_id();
            $admin_role_data['create_time'] = get_date_time();

            IDb::dbStartTrans();
            $admin_role_add = IDb::getInstance("admin_role")->setDbData($admin_role_data)->add();
            if($admin_role_add === false){
                IDb::dbRollback();
                error("创建管理员角色失败！");
            }

            // 添加首页，编辑我的信息，修改密码权限
            $menu = [1,2,3,4,5,6,7,8];
            $node = [1,2,3,4,5];

            //添加管理员角色权限
            $admin_access_data['admin_role_id'] = $admin_role_add;
            $admin_access_data['menu'] = implode(",",$menu);
            $admin_access_data['node'] = implode(",",$node);
            $admin_role_add = IDb::getInstance("admin_role_menu")->setDbData($admin_access_data)->add();
            if($admin_role_add === false){
                IDb::dbRollback();
                error("添加默认权限失败！");
            }
            IDb::dbCommit();
        }else{
            //修改保存
            $admin_role_where['admin_role_id'] = $role_id;
            $admin_role_data['role_name'] = $role_name;
            $admin_role_data['admin_super'] = $admin_super;
            $admin_role_data['remark'] = $remark;
            $admin_role_data['update_admin']=get_login_admin_id();
            $admin_role_data['update_time']=get_date_time();
            $admin_role_upd = IDb::getInstance("admin_role")->setDbWhere($admin_role_where)->setDbData($admin_role_data)->upd();
            if($admin_role_upd === false){
                error("修改管理员角色信息失败！");
            }
        }

        //删除缓存
        IAdminRoleCache::deleteInfo($role_id);

        //画面跳转
        $this->redirect("role_list");
    }

    /**
     * @功能：管理员角色详情
     * @开发者：cxl
     */
    public function role_info(){
        //接收参数
        $role_id = IRequest::get('role_id',IRequest::NOT_EMPTY,"管理员角色编号不能为空！");

        //取得管理员角色数据
        $admin_role_info = IAdminRoleCache::getInfo($role_id);

        //设置layout
        $this->layout("layout_empty");

        //模板渲染
        $this->assign('role_info',$admin_role_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：管理员角色权限设置
     * @开发者：cxl
     */
    public function role_access_edit(){
        //接收参数
        $role_id= IRequest::get('role_id',IRequest::NOT_EMPTY,"管理员角色编号不能为空！");

        //取得管理员角色数据
        $admin_role_info = IAdminRoleCache::getInfo($role_id);
        if(empty($admin_role_info)){
            error("管理员角色不存在！");
        }

        //取得系统菜单列表
        $menu_where['is_delete'] = array("eq",1);
        $menu_list = IDb::getInstance("admin_menu")
            ->setDbFiled("menu_id,name,parent_id,if(default_node is null,'N',concat('N',default_node)) as default_node")
            ->setDbWhere($menu_where)
            ->setDbOrder("order_by")
            ->sel();

        //取得系统菜单节点
        $menu_node_where['an.is_delete'] = IsDelete::No;
        $menu_node = IDb::getInstance("admin_menu_node as amn")
            ->setDbFiled("concat('N',amn.node_id) as menu_id,concat(an.title,'【',an.model_name,'：',an.action_name,'】') as name,amn.menu_id as parent_id,an.model_name,an.action_name,'N' as default_node")
            ->setDbJoin("admin_node as an","an.node_id=amn.node_id")
            ->setDbWhere($menu_node_where)
            ->sel();

        //整理数据
        $menu_list = array_merge($menu_list,$menu_node);

        //取得选中系统菜单
        $menu_node_map["admin_role_id"] = $role_id;
        $menu_node_info = IDb::getInstance("admin_role_menu")->setDbWhere($menu_node_map)->row();

        //整理数据
        $menu = explode(",",$menu_node_info['menu']);
        $node = explode(",",$menu_node_info['node']);
        $node = array_map(function($item){return "N{$item}";},$node);

        //合并数据
        $node_list = array_merge($menu,$node);

        //模板渲染
        $this->assign('role_id',$role_id);
        $this->assign('menu_list',$menu_list);
        $this->assign('node_list',$node_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：管理员角色权限提交
     * @开发者：cxl
     */
    public function role_access_submit(){
        //接收参数
        $role_id= IRequest::get('role_id',IRequest::NOT_EMPTY,"管理员角色编号不能为空！");
        $data= IRequest::get('data/a');

        //判断是否为超级管理员
        $admin_super = get_login_admin_super();
        if($admin_super != AdminSuper::Super){
            error("只有超级管理员才有权限！");
        }

        //取得管理员角色数据
        $admin_role_info = IAdminRoleCache::getInfo($role_id);
        if(empty($admin_role_info)){
            error("管理员角色不存在！");
        }

        //判断权限数据是否正确
        if(!is_array($data)){
            error("权限数据错误！");
        }

        //整理数据
        $menu = array();
        $node = array();
        foreach($data as $item){
            //判断是否为节点
            if(stripos($item,"N") === false){
                $menu[] = $item;
            }else{
                $node[] = str_ireplace("N","",$item);
            }
        }

        // 添加首页，编辑我的信息，修改密码权限
        $menu = array_merge($menu,[1,2,3,4,5,6,7,8]);
        $node = array_merge($node,[1,2,3,4,5]);

        //判断管理员角色权限是否存在
        //$role_menu_info = IAdminRoleCache::getInfo($role_id);
        $role_menu_info = IDb::getInstance("admin_role_menu")->setDbWhere(['admin_role_id'=>$role_id])->row();
        if(empty($role_menu_info)){
            //添加管理员角色权限
            $admin_role_data['admin_role_id'] = $role_id;
            $admin_role_data['menu'] = implode(",",$menu);
            $admin_role_data['node'] = implode(",",$node);
            $admin_role_add = IDb::getInstance("admin_role_menu")->setDbData($admin_role_data)->add();
            if($admin_role_add === false){
                error("修改管理员角色权限失败1！");
            }
        }else{
            //修改管理员角色权限
            $admin_role_data['menu'] = implode(",",$menu);
            $admin_role_data['node'] = implode(",",$node);
            $admin_role_upd = IDb::getInstance("admin_role_menu")->setDbWhere("admin_role_id='{$role_id}'")->setDbData($admin_role_data)->upd();
            if($admin_role_upd === false){
                error("修改管理员角色权限失败2！");
            }
        }

        //画面跳转
        $this->redirect("role_list");
    }

    /**
     * @功能：管理员列表
     * @开发者：cxl
     */
    public function admin_list(){
        //接收参数
        $role_id = IRequest::get('role_id');
        $admin_super = IRequest::get('admin_super');
        $real_name = IRequest::get('real_name');
        $admin_phone = IRequest::get('admin_phone');

        //取得管理员数据
        $where = array();
        if(!empty($role_id)) $where["an.admin_role_id"] = array("eq",$role_id);
        if(!empty($admin_super)) $where["an.admin_super"] = array("eq",$admin_super);
        if(!empty($real_name)) $where["an.real_name"] = array("like","%{$real_name}%");
        if(!empty($admin_phone)) $where["an.admin_phone"] = array("like","%{$admin_phone}%");


        //取得数据
        $admin_list = IDb::getInstance("admin as an")
            ->setDbFiled("an.*,ar.role_name,an.admin_super")
            ->setDbJoin("admin_role as ar","an.admin_role_id=ar.admin_role_id","left")
            ->setDbWhere($where)
            ->pag();

        //取得管理员数据
        $role_list = IDb::getInstance("admin_role")->sel();

        //模板渲染
        $this->assign('role_id',$role_id);
        $this->assign('admin_super',$admin_super);
        $this->assign('real_name',$real_name);
        $this->assign('admin_phone',$admin_phone);
        $this->assign('admin_list',$admin_list);
        $this->assign('role_list',$role_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加管理员
     * @开发者：cxl
     */
    public function admin_add(){
        //取得管理员数据
        $role_list = IDb::getInstance("admin_role")->sel();

        //取得默认密码
        $admin_password = IConfig::getValue('AdminDefaultPassword');

        //模板渲染
        $this->assign('admin_password',$admin_password);
        $this->assign('role_list',$role_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑管理员
     * @开发者：cxl
     */
    public function admin_edit(){
        //接收参数
        $admin_id = IRequest::get('admin_id',IRequest::NOT_EMPTY,"管理员编号不能为空！");

        //取得管理员角色数据
        $admin_info = IAdminCache::getInfo($admin_id);
        if(empty($admin_info['admin_id'])){
            error("管理员不存在！");
        }

        //取得管理员数据
        $role_list = IDb::getInstance("admin_role")->sel();

        //模板渲染
        $this->assign('admin_id',$admin_id);
        $this->assign('role_list',$role_list);
        $this->assign('admin_info',$admin_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：管理员保存
     * 开发者：cxl
     */
    public function admin_submit(){
        //接收参数
        $admin_id = IRequest::get("admin_id");
        $real_name = IRequest::get("real_name",IRequest::NOT_EMPTY,"真实姓名不能为空！");
        $phone = IRequest::get("phone",IRequest::NOT_EMPTY,"手机不能为空！");
        $admin_role_id= IRequest::get("admin_role_id",IRequest::NOT_EMPTY,"请选择管理员角色！");
        $remark = IRequest::get("remark");

        //取得管理员角色类型
        $role_info = IAdminRoleCache::getInfo($admin_role_id);
        if(empty($role_info)){
            error("取得管理员角色信息失败！");
        }

        //查询用户名账号信息
        $admin_where['admin_phone'] = $phone;
        $admin_info = IDb::getInstance("admin")->setDbWhere($admin_where)->row();

        //判断用户是否已经被注册了
        if(empty($admin_id)){
            //判断用户名称是否被使用了
            if(!empty($admin_info)){
                error("手机号已经被使用了！");
            }

            //获取后台用户默认密码
            $admin_password = IConfig::getValue('AdminDefaultPassword');
            if(empty($admin_password)){
                error('未配置后台用户密码,请联系管理员！');
            }

            //新增保存
            $admin_data['real_name']=$real_name;
            $admin_data['admin_phone']=$phone;
            $admin_data['admin_role_id']=$admin_role_id;
            $admin_data['admin_super']=$role_info['admin_super'];
            $admin_data['remark']=$remark;
            $admin_data['admin_pwd'] = md5(md5($admin_password));
            $admin_data['create_admin']=get_login_admin_id();
            $admin_data['create_time']=get_date_time();
            $admin_id = IDb::getInstance("admin")->setDbData($admin_data)->add();
            if($admin_id === false){
                error("创建管理员失败！");
            }
        }else {
            //判断用户名称是否被使用了
            if(!empty($admin_info) && $admin_id != $admin_info['admin_id']){
                error("账户名已经被使用了！");
            }

            //修改保存
            $admin_where = null;
            $admin_where['admin_id'] = $admin_id;
            $admin_data['real_name']=$real_name;
            $admin_data['admin_phone']=$phone;
            $admin_data['admin_role_id']=$admin_role_id;
            $admin_data['admin_super']=$role_info['admin_super'];
            $admin_data['remark']=$remark;
            $admin_data['update_admin'] = get_login_admin_id();
            $admin_data['update_time'] = get_date_time();
            $admin_upd = IDb::getInstance("admin")->setDbWhere($admin_where)->setDbData($admin_data)->upd();
            if ($admin_upd === false) {
                error("编辑管理员信息失败！");
            }
        }

        //清除缓存
        IAdminCache::deleteInfo($admin_id);

        //画面跳转
        $this->redirect("admin_list");
    }

    /**
     * @功能：管理员详情
     * @开发者：cxl
     */
    public function admin_info(){
        //接收参数
        $admin_id = IRequest::get('admin_id',IRequest::NOT_EMPTY,"管理员编号不能为空！");

        //取得管理员数据
        $role_list = IDb::getInstance("admin_role")->sel();

        //取得管理员角色数据
        $admin_info = IAdminCache::getInfo($admin_id);

        //设置layout
        $this->layout("layout_empty");

        //模板渲染
        $this->assign('admin_id',$admin_id);
        $this->assign('role_list',$role_list);
        $this->assign('admin_info',$admin_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：删除管理员
     * @开发者：cxl
     */
    public function admin_del(){
        //接收参数
        $admin_id = IRequest::get("admin_id",IRequest::NOT_EMPTY,"管理员编号不能为空！");

        //取得管理员角色使用信息
        $admin_where["admin_id"] = $admin_id;
        $admin_data['is_delete'] = IsDelete::Yes;
        $admin_data['update_admin']=get_login_admin_id();
        $admin_data['update_time']=get_date_time();
        $admin_upd = IDb::getInstance("admin")->setDbWhere($admin_where)->setDbData($admin_data)->upd();
        if($admin_upd === false){
            error("修改管理员信息失败！");
        }

        //清除缓存
        IAdminCache::deleteInfo($admin_id);

        //画面跳转
        $this->redirect("admin_list");
    }

    /**
     * @功能：还原管理员
     * @开发者：cxl
     */
    public function admin_reset(){
        //接收参数
        $admin_id = IRequest::get("admin_id",IRequest::NOT_EMPTY,"管理员编号不能为空！");

        //取得管理员角色使用信息
        $admin_where["admin_id"] = $admin_id;
        $admin_data['is_delete'] = IsDelete::No;
        $admin_data['update_admin']=get_login_admin_id();
        $admin_data['update_time']=get_date_time();
        $admin_upd = IDb::getInstance("admin")->setDbWhere($admin_where)->setDbData($admin_data)->upd();
        if($admin_upd === false){
            error("修改管理员信息失败！");
        }

        //清除缓存
        IAdminCache::deleteInfo($admin_id);

        //画面跳转
        $this->redirect("admin_list");
    }

    /**
     * @功能：重置管理员密码
     * @开发者：cxl
     */
    public function admin_reset_pwd(){
        //接收参数
        $admin_id = IRequest::get("admin_id",IRequest::NOT_EMPTY,"管理员编号不能为空！");

        //获取后台用户默认密码
        $admin_password = IConfig::getValue('AdminDefaultPassword');
        if(empty($admin_password)){
            error('未配置后台用户密码,请联系管理员！');
        }

        //取得管理员角色使用信息
        $admin_where["admin_id"] = $admin_id;
        $admin_data['admin_pwd'] = md5(md5($admin_password));
        $admin_data['update_admin']=get_login_admin_id();
        $admin_data['update_time']=get_date_time();
        $admin_upd = IDb::getInstance("admin")->setDbWhere($admin_where)->setDbData($admin_data)->upd();
        if($admin_upd === false){
            error("重置密码失败！");
        }

        //清除缓存
        IAdminCache::deleteInfo($admin_id);

        //充值密码
        $this->success('重置密码成功！');
    }

    /**
     * @功能：系统菜单列表
     * @开发者：cxl
     */
    public function menu_list(){
        //接收参数
        $menu_id = IRequest::get('menu_id');

        //取得省份
        $admin_menu_where['level'] = array("<","3");
        $select_menu_list = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->sel();

        //取得省份
        $admin_menu_list = IDb::getInstance("admin_menu")->sel();

        //部门树参数配置
        $href_root = Url("menu_add",array('menu_id'=>'0'));
        $href_add = Url("menu_add",array('menu_id'=>'{menu_id}'));
        $href_edit = Url("menu_edit",array('menu_id'=>'{menu_id}'));
        $href_default = Url("menu_node_default",array('menu_id'=>'{menu_id}'));
        $href_info = Url("menu_info",array('menu_id'=>'{menu_id}'));
        $href_del = Url("menu_del",array('menu_id'=>'{menu_id}'));
        $menu_reset = Url("menu_reset",array('menu_id'=>'{menu_id}'));

        //配置树参数
        ListTree::set("node",null,"menu_id"); //节点字段名
        ListTree::set("node_root",null,array("系统文章分类根节点","<a href='{$href_root}' class='blue' >添加下级类型</a>")); //根节点字段名
        ListTree::set("node_filed","name",array("类型名称","40%")); //字段列表
        ListTree::set("node_filed",
            "_href_",array(
                "操作","20%",
                "
                <a href='{$href_add}' class='blue' >添加下级类型</a>
                <a href='{$href_edit}' class='blue'>编辑菜单及功能点</a>
                <a href='{$href_default}' class='blue'>设置默认节点</a>
                <a href='{$href_del}' class='blue info'>删除</a>
                <a href='{$href_info}' class='blue'>详情</a>
                ",
                "<a href='{$menu_reset}'><font color='red'>还原</font></a>"
            )
        );

        //模版渲染
        $this->assign("menu_id",$menu_id);
        $this->assign("select_menu_list",$select_menu_list);
        $this->assign("admin_menu_list",$admin_menu_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加系统菜单
     * @开发者：陈旭林
     */
    public function menu_add(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //初期化变量
        $level = 1;
        $parent_id = 0;
        $parent_name = "系统系统菜单根节点";

        //判断是否为编辑
        if(empty($menu_id)){
            $level = 1;
            $parent_id = 0;
            $parent_name = "系统系统菜单根节点";
        }else{
            //取得等级
            $admin_menu_where["menu_id"] = $menu_id;
            $admin_menu_info = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->row();
            if(empty($admin_menu_info)){
                error("取得系统文章分类信息失败！");
            }else{
                $level = (intval($admin_menu_info['level']) + 1);
                $parent_id = $menu_id;
                $parent_name = $admin_menu_info['name'];
            }
        }

        //判断系统菜单等级是否大于3级
        if($level > 3){
            error("最多只允许三级系统菜单！");
        }

        //模板渲染
        $this->assign('level',$level);
        $this->assign('parent_id',$parent_id);
        $this->assign('parent_name',$parent_name);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑系统菜单
     * @开发者：陈旭林
     */
    public function menu_edit(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_info = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->row();
        if(empty($admin_menu_info)){
            error("系统菜单信息失败！");
        }

        //判断系统菜单等级是否等于3级
        if($admin_menu_info['level'] == 3){
            //取得系统菜单信息
            $admin_menu_node_where["menu_id"] = $menu_id;
            $admin_menu_node_list = IDb::getInstance("admin_menu_node")->setDbWhere($admin_menu_node_where)->sel();
            if(empty($admin_menu_node_list)){
                error("系统菜单节点信息失败！");
            }

            //取得节点信息
            $admin_node_where["node_id"] = array("in",array_column($admin_menu_node_list,"node_id"));
            $admin_node_list = IDb::getInstance("admin_node")->setDbWhere($admin_node_where)->sel();
            if(empty($admin_node_list)){
                error("系统菜单节点信息失败！");
            }

            //模板渲染
            $this->assign('admin_node_list',$admin_node_list);
        }

        //模板渲染
        $this->assign('menu_id',$menu_id);
        $this->assign('admin_menu_info',$admin_menu_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加系统菜单提交
     * @开发者：陈旭林
     */
    public function menu_add_submit(){
        //接收参数
        $menu_id = IRequest::get("menu_id");
        $name = IRequest::get("name",IRequest::NOT_EMPTY,"系统菜单名称不正确！");
        $order_by = IRequest::get("order_by");

        //开启事物处理
        IDb::dbStartTrans();

        //判断是否为添加
        if(empty($menu_id)){
            //接收参数
            $parent_id = IRequest::get("parent_id",IRequest::NOT_EMPTY,"系统菜单上层编号不正确！");
            $level = IRequest::get("level",IRequest::NOT_EMPTY,"系统菜单等级编号不正确！");

            //取得等级
            $admin_menu_data["name"] = $name;
            $admin_menu_data["parent_id"] = $parent_id;
            $admin_menu_data["level"] = $level;
            $admin_menu_data["order_by"] = $order_by;
            $admin_menu_add = IDb::getInstance("admin_menu")->setDbData($admin_menu_data)->add();
            if($admin_menu_add === false){
                //事物回滚
                IDb::dbRollback();

                //返回错误信息
                error("添加系统菜单失败！");
            }

            //判断等级
            if($level == 3){
                //接收参数
                $node_data = array();
                $node = IRequest::get("node");

                //判断参数是否正确
                if(!empty($node) && is_array($node)){
                    //优惠活动
                    if(is_array($node['title']) && is_array($node['model_name']) && is_array($node['action_name']) && count($node['title']) == count($node['model_name']) && count($node['title']) == count($node['action_name'])){
                        //整理数据
                        foreach ($node['title'] as $key => $value) {
                            $node_data[] = array('title' => $value, 'model_name' => $node['model_name'][$key], 'action_name' => $node['action_name'][$key]);
                        }
                    }

                    //循环添加系统菜单节点数据
                    foreach($node_data as $item){
                        //判断系统菜单设置是否正确
                        if(empty($item['title']) || empty($item['model_name']) || empty($item['action_name'])){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("添加系统菜单失败！");
                        }

                        //添加系统菜单
                        $admin_node_data = null;
                        $admin_node_data["title"] = $item['title'];
                        $admin_node_data["model_name"] = $item['model_name'];
                        $admin_node_data["action_name"] = $item['action_name'];
                        $admin_node_add = IDb::getInstance("admin_node")->setDbData($admin_node_data)->add();
                        if($admin_node_add === false){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("添加系统菜单失败！");
                        }

                        //添加管理节点数据
                        $admin_menu_node_data = null;
                        $admin_menu_node_data["menu_id"] = $admin_menu_add;
                        $admin_menu_node_data["node_id"] = $admin_node_add;
                        $admin_menu_node_add = IDb::getInstance("admin_menu_node")->setDbData($admin_menu_node_data)->add();
                        if($admin_menu_node_add === false){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("添加系统菜单失败！");
                        }
                    }
                }
            }
        }else{
            //取得等级
            $admin_menu_where['menu_id'] = $menu_id;
            $admin_menu_data["name"] = $name;
            $admin_menu_data["order_by"] = $order_by;
            $admin_menu_upd = IDb::getInstance("admin_menu")->setDbData($admin_menu_data)->setDbWhere($admin_menu_where)->upd();
            if($admin_menu_upd === false){
                //事物回滚
                IDb::dbRollback();

                //返回错误信息
                error("修改系统菜单失败！");
            }

            //取得系统菜单信息
            $admin_menu_where['menu_id'] = $menu_id;
            $admin_menu_info = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->row();
            if($admin_menu_info === false){
                //事物回滚
                IDb::dbRollback();

                //返回错误信息
                error("修改系统菜单失败！");
            }

            //判断等级
            if($admin_menu_info['level'] === 3){
                //接收参数
                $node_data = array();
                $node = IRequest::get("node");

                //判断参数是否正确
                if(!empty($node) && is_array($node)){
                    //优惠活动
                    if(is_array($node['title']) && is_array($node['model_name']) && is_array($node['action_name']) && count($node['title']) == count($node['model_name']) && count($node['title']) == count($node['action_name'])){
                        //整理数据
                        foreach ($node['title'] as $key => $value) {
                            $node_data[] = array('title' => $value, 'model_name' => $node['model_name'][$key], 'action_name' => $node['action_name'][$key]);
                        }
                    }

                    //取得系统菜单节点数据
                    $admin_menu_node_where["menu_id"] = $menu_id;
                    $admin_menu_node_list = IDb::getInstance("admin_menu_node")->setDbWhere($admin_menu_node_where)->sel();
                    if($admin_menu_node_list === false){
                        //事物回滚
                        IDb::dbRollback();

                        //返回错误信息
                        error("修改系统菜单失败！");
                    }

                    //清除多余数据
                    $admin_menu_node_where["menu_id"] = $menu_id;
                    $admin_menu_node_where["node_id"] = array("in",array_column($admin_menu_node_list,"node_id"));
                    $admin_menu_node_del = IDb::getInstance("admin_menu_node")->setDbWhere($admin_menu_node_where)->del();
                    if($admin_menu_node_del === false){
                        //事物回滚
                        IDb::dbRollback();

                        //返回错误信息
                        error("修改系统菜单失败！");
                    }

                    //清除多余数据
                    $admin_node_where["node_id"] = array("in",array_column($admin_menu_node_list,"node_id"));
                    $admin_node_del = IDb::getInstance("admin_node")->setDbWhere($admin_node_where)->del();
                    if($admin_node_del === false){
                        //事物回滚
                        IDb::dbRollback();

                        //返回错误信息
                        error("修改系统菜单失败！");
                    }

                    //循环添加系统菜单数据
                    foreach($node_data as $item){
                        //判断系统菜单设置是否正确
                        if(empty($item['title']) || empty($item['model_name']) || empty($item['action_name'])){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("修改系统菜单失败！");
                        }

                        //添加系统菜单
                        $admin_node_data = null;
                        $admin_node_data["title"] = $item['title'];
                        $admin_node_data["model_name"] = $item['model_name'];
                        $admin_node_data["action_name"] = $item['action_name'];
                        $admin_node_add = IDb::getInstance("admin_node")->setDbData($admin_node_data)->add();
                        if($admin_node_add === false){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("修改系统菜单失败！");
                        }

                        //添加管理节点数据
                        $admin_menu_node_data = null;
                        $admin_menu_node_data["menu_id"] = $menu_id;
                        $admin_menu_node_data["node_id"] = $admin_node_add;
                        $admin_menu_node_add = IDb::getInstance("admin_menu_node")->setDbData($admin_menu_node_data)->add();
                        if($admin_menu_node_add === false){
                            //事物回滚
                            IDb::dbRollback();

                            //返回错误信息
                            error("添加系统菜单失败！");
                        }
                    }
                }
            }
        }

        //提交事物处理
        IDb::dbCommit();

        //充值密码
        $this->success('操作成功！',Url("menu_list"));
    }

    /**
     * @功能：删除系统菜单提交
     * @开发者：陈旭林
     */
    public function menu_del(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_data["is_delete"] = IsDelete::Yes;
        $admin_menu_upd = IDb::getInstance("admin_menu")->setDbData($admin_menu_data)->setDbWhere($admin_menu_where)->upd();
        if($admin_menu_upd === false){
            error("删除系统菜单失败！");
        }

        //充值密码
        $this->success('操作成功！',Url("menu_list"));
    }

    /**
     * @功能：还原系统菜单提交
     * @开发者：陈旭林
     */
    public function menu_reset(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_data["is_delete"] = IsDelete::No;
        $admin_menu_upd = IDb::getInstance("admin_menu")->setDbData($admin_menu_data)->setDbWhere($admin_menu_where)->upd();
        if($admin_menu_upd === false){
            error("删除系统菜单失败！");
        }

        //充值密码
        $this->success('操作成功！',Url("menu_list"));
    }

    /**
     * @功能：编辑默认节点
     * @开发者：陈旭林
     */
    public function menu_node_default(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_info = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->row();
        if(empty($admin_menu_info)){
            error("取得系统文章分类信息失败！");
        }

        //判断系统菜单等级是否大于3级
        if($admin_menu_info['level'] > 3){
            error("三级系统菜单才需要设置默认节点！");
        }

        //取得系统菜单节点信息
        $admin_menu_node_where["menu_id"] = $menu_id;
        $admin_menu_node_list = IDb::getInstance("admin_menu_node")->setDbWhere($admin_menu_node_where)->sel();
        if($admin_menu_node_list === false){
            error("设置系统菜单默认节点失败！");
        }

        //清除多余数据
        $admin_node_where["node_id"] = array("in",array_column($admin_menu_node_list,"node_id"));
        $admin_node_list = IDb::getInstance("admin_node")->setDbWhere($admin_node_where)->sel();
        if($admin_node_list === false){
            error("设置系统菜单默认节点失败！");
        }

        //模板渲染
        $this->assign('admin_menu_info',$admin_menu_info);
        $this->assign('admin_node_list',$admin_node_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑默认节点提交
     * @开发者：陈旭林
     */
    public function menu_node_default_submit(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");
        $default_node = IRequest::get("default_node",IRequest::NUMBER,"节点编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_data["default_node"] = $default_node;
        $admin_menu_upd = IDb::getInstance("admin_menu")->setDbData($admin_menu_data)->setDbWhere($admin_menu_where)->upd();
        if($admin_menu_upd === false){
            error("设置系统菜单默认节点失败！");
        }

        //充值密码
        $this->success('操作成功！',Url("menu_list"));
    }

    /**
     * @功能：系统菜单详情
     * @开发者：陈旭林
     */
    public function menu_info(){
        //接收参数
        $menu_id = IRequest::get("menu_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //取得等级
        $admin_menu_where["menu_id"] = $menu_id;
        $admin_menu_info = IDb::getInstance("admin_menu")->setDbWhere($admin_menu_where)->row();
        if(empty($admin_menu_info)){
            error("系统菜单信息失败！");
        }

        //判断系统菜单等级是否等于3级
        if($admin_menu_info['level'] == 3){
            //取得系统菜单信息
            $admin_menu_node_where["menu_id"] = $menu_id;
            $admin_menu_node_list = IDb::getInstance("admin_menu_node")->setDbWhere($admin_menu_node_where)->sel();
            if(empty($admin_menu_node_list)){
                error("系统菜单节点信息失败！");
            }

            //取得节点信息
            $admin_node_where["node_id"] = array("in",array_column($admin_menu_node_list,"node_id"));
            $admin_node_list = IDb::getInstance("admin_node")->setDbWhere($admin_node_where)->sel();
            if(empty($admin_node_list)){
                error("系统菜单节点信息失败！");
            }

            //模板渲染
            $this->assign('admin_node_list',$admin_node_list);
        }

        //模板渲染
        $this->assign('menu_id',$menu_id);
        $this->assign('admin_menu_info',$admin_menu_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：银行列表
     * @开发者：cxl
     */
    public function bank_list(){
        //接收参数
        $bank_id = IRequest::get('bank_id');
        $bank_name = IRequest::get('bank_name');
        $bank_type_id = IRequest::get('bank_type_id');
        $is_credit = IRequest::get('is_credit');
        $is_house = IRequest::get('is_house');
        $is_hot = IRequest::get('is_hot');

        //搜索条件
        $bank_where = null;
        if(!empty($bank_id)) $bank_where['bk.bank_id'] = array("eq",$bank_id);
        if(!empty($bank_name)) $bank_where['bk.bank_name'] = array("like","%{$bank_name}%");
        if(!empty($bank_type_id)) $bank_where['bk.bank_type_id'] = array("eq",$bank_type_id);
        if(!empty($is_credit)) $bank_where['bk.is_credit'] = array("eq",$is_credit);
        if(!empty($is_house)) $bank_where['bk.is_house'] = array("eq",$is_house);
        if(!empty($is_hot)) $bank_where['bk.is_hot'] = array("eq",$is_hot);

        //实例化对象
        $bank_list = IDb::getInstance("bank as bk")
            ->setDbFiled("bk.*,bt.bank_type_name")
            ->setDbJoin("bank_type as bt","bk.bank_type_id=bt.bank_type_id")
            ->setDbWhere($bank_where)
            ->setDbOrder("order_by desc,bank_type_id,bank_id")
            ->pag();

        //取得银行类型
        $bank_type_list = IBankTypeCache::getList();

        //模版渲染
        $this->assign("bank_id",$bank_id);
        $this->assign("bank_name",$bank_name);
        $this->assign("bank_type_id",$bank_type_id);
        $this->assign("is_credit",$is_credit);
        $this->assign("is_hot",$is_hot);
        $this->assign("is_house",$is_house);
        $this->assign("bank_list",$bank_list);
        $this->assign("bank_type_list",$bank_type_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：银行编辑
     * @开发者：cxl
     */
    public function bank_add(){
        //取得银行类型
        $bank_type_list = IBankTypeCache::getList();

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

        //模版渲染
        $this->assign("bank_type_list",$bank_type_list);
        $this->assign("area_list",$area_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：银行编辑
     * @开发者：cxl
     */
    public function bank_edit(){
        //接收参数
        $bank_id = IRequest::get('bank_id',IRequest::NOT_EMPTY,"银行编号不能为空！");

        //取得银行信息
        $bank_info = IBankCache::getInfo($bank_id);

        //取得银行类型
        $bank_type_list = IBankTypeCache::getList();

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

//        $bank_house_rate_where = null;
//        $bank_house_rate_where['bank_id'] = $bank_id;
//        $bank_house_rate_list = IDb::getInstance('bank_house_rate')->setDbWhere($bank_house_rate_where)->sel();
//        if($bank_house_rate_list === false){
//            $bank_house_rate_list = [];
//        }

        //模版渲染
        $this->assign("area_list",$area_list);
        $this->assign("bank_id",$bank_id);
        $this->assign("bank_info",$bank_info);
        $this->assign("bank_type_list",$bank_type_list);
//        $this->assign("bank_house_rate_list",$bank_house_rate_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：银行编辑-提交
     * @开发者：cxl
     */
    public function bank_edit_submit(){
        //接收参数
        $bank_id = IRequest::get('bank_id');
        $bank_type_id = IRequest::get('bank_type_id',IRequest::NOT_EMPTY,"银行类型编号不能为空！");
        $bank_url = IRequest::get('bank_url');
        $bank_word_url = IRequest::get('bank_word_url');
        $bank_outline = IRequest::get('bank_outline');
        $pass_rate = IRequest::get('pass_rate');
        $discount_rate = IRequest::get('discount_rate');
        $send_rate = IRequest::get('send_rate');
        $ratify_velocity = IRequest::get('ratify_velocity');
        $general = IRequest::get('general');
        $gold = IRequest::get('gold');
        $platinum = IRequest::get('platinum');
        $heat = IRequest::get('heat');
        $specially = IRequest::get('specially');
        $credit_schedule_url = IRequest::get('credit_schedule_url');
        $credit_schedule_url_pc = IRequest::get('credit_schedule_url_pc');
        $is_credit = IRequest::get('is_credit');
        $is_house = IRequest::get('is_house');
        $is_hot = IRequest::get('is_hot');
        $order_by = IRequest::get('order_by');
        $remark = IRequest::get('remark');
        $area = IRequest::get('area');

        //判断是否为修改
        if(empty($bank_id)) {
            //接收参数
            $bank_name = IRequest::get('bank_name',IRequest::NOT_EMPTY,"银行名称不能为空！");

            //判断名称是否已经存在
            $bank_where = null;
            $bank_where['bank_name'] = $bank_name;
            $bank_con = IDb::getInstance('bank')->setDbWhere($bank_where)->con();
            if($bank_con > 0){
                error("{$bank_name}已经存在！");
            }

            //设置数据
            $bank_data['bank_type_id'] = $bank_type_id;
            $bank_data['bank_name'] = $bank_name;
            $bank_data['bank_url'] = $bank_url;
            $bank_data['bank_word_url'] = $bank_word_url;
            $bank_data['bank_outline'] = $bank_outline;
            $bank_data['pass_rate'] = $pass_rate;
            $bank_data['discount_rate'] = $discount_rate;
            $bank_data['send_rate'] = $send_rate;
            $bank_data['ratify_velocity'] = $ratify_velocity;
            $bank_data['general'] = $general;
            $bank_data['gold'] = $gold;
            $bank_data['platinum'] = $platinum;
            $bank_data['heat'] = $heat;
            $bank_data['specially'] = $specially;
            $bank_data['credit_schedule_url'] = $credit_schedule_url;
            $bank_data['credit_schedule_url_pc'] = $credit_schedule_url_pc;
            $bank_data['is_credit'] = $is_credit;
            $bank_data['is_house'] = $is_house;
            $bank_data['is_hot'] = $is_hot;
            $bank_data['order_by'] = $order_by;
            $bank_data['remark'] = $remark;
            $bank_data['update_admin'] = get_login_admin_id();
            $bank_data['update_time'] = get_date_time();

            //开启实物
            IDb::dbStartTrans();

            //添加银行信息
            $bank_add = IDb::getInstance("bank")->setDbData($bank_data)->add();
            if ($bank_add === false) {
                //事物回滚
                IDb::dbRollback();

                //返回错误信息
                error("操作失败！");
            }

        }else{
            //设置数据
            $bank_where['bank_id'] = $bank_id;
            $bank_data['bank_type_id'] = $bank_type_id;
            $bank_data['bank_url'] = $bank_url;
            $bank_data['bank_word_url'] = $bank_word_url;
            $bank_data['bank_outline'] = $bank_outline;
            $bank_data['pass_rate'] = $pass_rate;
            $bank_data['discount_rate'] = $discount_rate;
            $bank_data['send_rate'] = $send_rate;
            $bank_data['ratify_velocity'] = $ratify_velocity;
            $bank_data['general'] = $general;
            $bank_data['gold'] = $gold;
            $bank_data['platinum'] = $platinum;
            $bank_data['heat'] = $heat;
            $bank_data['specially'] = $specially;
            $bank_data['credit_schedule_url'] = $credit_schedule_url;
            $bank_data['credit_schedule_url_pc'] = $credit_schedule_url_pc;
            $bank_data['is_credit'] = $is_credit;
            $bank_data['is_house'] = $is_house;
            $bank_data['is_hot'] = $is_hot;
            $bank_data['order_by'] = $order_by;
            $bank_data['remark'] = $remark;
            $bank_data['update_admin'] = get_login_admin_id();
            $bank_data['update_time'] = get_date_time();


            //开启实物
            IDb::dbStartTrans();

            //取得银行信息
            $bank_upd = IDb::getInstance("bank")->setDbData($bank_data)->setDbWhere($bank_where)->upd();
            if ($bank_upd === false) {
                //事物回滚
                IDb::dbRollback();
                error("操作失败！");
            }

            //清除缓存
            IBankCache::deleteInfo($bank_id);
        }

        //清除缓存
        IBankCache::deleteList();
        IBankCache::deleteCreditListAll();

        //实物提交
        IDb::dbCommit();

        //充值密码
        $this->success('操作成功！',Url("bank_list"));
    }

    /**
     * @功能：银行删除
     * @开发者：cxl
     */
    public function bank_del(){
        //接收参数
        $bank_id = IRequest::get('bank_id',IRequest::NOT_EMPTY,"银行编号不能为空！");

        //设置数据
        $bank_where['bank_id'] = $bank_id;
        $bank_data['is_delete'] = IsDelete::Yes;
        $bank_data['update_admin'] = get_login_admin_id();
        $bank_data['update_time'] = get_date_time();
        $bank_upd = IDb::getInstance("bank")->setDbData($bank_data)->setDbWhere($bank_where)->upd();
        if($bank_upd === false){
            error("操作失败！");
        }

        //清除缓存
        IBankCache::deleteInfo($bank_id);
        IBankCache::deleteList();
        IBankCache::deleteCreditListAll();

        //充值密码
        $this->success('操作成功！',Url("bank_list"));
    }

    /**
     * @功能：银行删除
     * @开发者：cxl
     */
    public function bank_recycle(){
        //接收参数
        $bank_id = IRequest::get('bank_id',IRequest::NOT_EMPTY,"银行编号不能为空！");

        //取得银行信息
        $bank_where['bank_id'] = $bank_id;
        $bank_data['is_delete'] = IsDelete::No;
        $bank_data['update_admin'] = get_login_admin_id();
        $bank_data['update_time'] = get_date_time();
        $bank_upd = IDb::getInstance("bank")->setDbData($bank_data)->setDbWhere($bank_where)->upd();
        if($bank_upd === false){
            error("操作失败！");
        }

        //清除缓存
        IBankCache::deleteInfo($bank_id);
        IBankCache::deleteList();
        IBankCache::deleteCreditListAll();

        //充值密码
        $this->success('操作成功！',Url("bank_list"));
    }

    /**
     * @功能：系统公告列表
     * @开发者：cxl
     */
    public function announcement_list(){
        //接收参数
        $app_type = IRequest::get("app_type");
        $announcement_title = IRequest::get("announcement_title");
        $announcement_content = IRequest::get("announcement_content");

        //查询条件
        $announcement_where = null;
        if(!empty($app_type))$announcement_where["app_type"] = $app_type;
        if(!empty($announcement_title))$announcement_where["announcement_title"] = array("like","%{$announcement_title}%");
        if(!empty($announcement_content))$announcement_where["announcement_content"] = array("like","%{$announcement_content}%");

        //取得公告列表
        $announcement_list = IDb::getInstance("com_announcement")->setDbWhere($announcement_where)->setDbOrder("announcement_id desc")->pag();

        //模板渲染
        $this->assign('announcement_title',$announcement_title);
        $this->assign('announcement_content',$announcement_content);
        $this->assign('announcement_list',$announcement_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加系统公告
     * @开发者：cxl
     */
    public function announcement_add(){
        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑系统公告
     * @开发者：cxl
     */
    public function announcement_edit(){
        //接收参数
        $announcement_id = IRequest::get('announcement_id',IRequest::NOT_EMPTY,"公告编号不能为空！");

        //取得角色数据
        $announcement_where["announcement_id"] = $announcement_id;
        $announcement_info =  IDb::getInstance("com_announcement")->setDbWhere($announcement_where)->row();
        if(empty($announcement_info['announcement_id'])){
            error("系统公告不存在！");
        }

        //模板渲染
        $this->assign('announcement_id',$announcement_id);
        $this->assign('announcement_info',$announcement_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：系统公告保存
     * 开发者：cxl
     */
    public function announcement_submit(){
        //接收参数
        $announcement_id = IRequest::get("announcement_id");
        $app_type = IRequest::get("app_type",IRequest::NOT_EMPTY,"APP类型不能为空！");
        $announcement_title = IRequest::get("announcement_title",IRequest::NOT_EMPTY,"系统公告标题不能为空！");
        $announcement_content = IRequest::get("announcement_content",IRequest::NOT_EMPTY,"系统公告内容不能为空！");
        $announcement_photo = IRequest::get("announcement_photo");
        $announcement_url = IRequest::get("announcement_url");

        //判断类型
        if(!in_array($app_type,array(AppType::XD,AppType::YH,AppType::HZ))){
            error("APP类型错误！");
        }

        //实例化对象
        $announcement_data['app_type'] = $app_type;
        $announcement_data['announcement_title'] = $announcement_title;
        $announcement_data['announcement_content']= $announcement_content;
        $announcement_data['announcement_photo']= $announcement_photo;
        $announcement_data['announcement_url']= $announcement_url;

        //判断是否为编辑
        if(empty($announcement_id)){
            //新增保存
            $announcement_data['create_time'] = get_date_time();
            $announcement_data['is_delete'] = IsDelete::No;
            $announcement_id = IDb::getInstance("com_announcement")->setDbData($announcement_data)->add();
            if($announcement_id === false){
                error("创建系统公告信息失败！");
            }
        }else {
            $announcement_upd = IDb::getInstance("com_announcement")->setDbWhere("announcement_id='{$announcement_id}'")->setDbData($announcement_data)->upd();
            if ($announcement_upd === false) {
                error("编辑系统公告信息失败！");
            }
        }

        //清除缓存
        IAnnouncementCache::deleteList($app_type);

        //画面跳转
        $this->redirect("announcement_list");
    }

    /**
     * @功能：系统公告详情
     * @开发者：cxl
     */
    public function announcement_info(){
        //接收参数
        $announcement_id = IRequest::get('announcement_id',IRequest::NOT_EMPTY,"系统公告编号不能为空！");

        //取得角色数据
        $announcement_info = IDb::getInstance("com_announcement")->setDbWhere("announcement_id='{$announcement_id}'")->row();

        //模板渲染
        $this->assign('announcement_info',$announcement_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：系统公告删除
     * @开发者：cxl
     */
    public function announcement_del(){
        //接收参数
        $announcement_id = IRequest::get("announcement_id",IRequest::NOT_EMPTY,"公告编号不能为空！");

        //取得角色使用信息
        $announcement_where["announcement_id"] = array("eq",$announcement_id);
        $announcement_data['is_delete'] = IsDelete::Yes;
        $announcement_data['update_admin']=get_login_admin_id();
        $announcement_data['update_time']=get_date_time();
        $announcement_upd = IDb::getInstance("com_announcement")->setDbWhere($announcement_where)->setDbData($announcement_data)->upd();
        if($announcement_upd === false){
            error("删除公告信息失败！");
        }

        //清除缓存
        IAnnouncementCache::deleteList(AppType::YH);
        IAnnouncementCache::deleteList(AppType::XD);

        //画面跳转
        $this->redirect("announcement_list");
    }

    /**
     * @功能：系统公告还原
     * @开发者：cxl
     */
    public function announcement_reset(){
        //接收参数
        $announcement_id = IRequest::get("announcement_id",IRequest::NOT_EMPTY,"公告编号不能为空！");

        //取得角色使用信息
        $announcement_where["announcement_id"] = array("eq",$announcement_id);
        $announcement_data['is_delete'] = IsDelete::No;
        $announcement_data['update_admin']=get_login_admin_id();
        $announcement_data['update_time']=get_date_time();
        $announcement_upd = IDb::getInstance("com_announcement")->setDbWhere($announcement_where)->setDbData($announcement_data)->upd();
        if($announcement_upd === false){
            error("删除公告信息失败！");
        }

        //清除缓存
        IAnnouncementCache::deleteList(AppType::YH);
        IAnnouncementCache::deleteList(AppType::XD);

        //画面跳转
        $this->redirect("announcement_list");
    }

    /**
     * @功能：短信发送日志
     * @开发者：cxl
     */
    public function sms_list(){
        //接收参数
        $phone = IRequest::get("phone");

        //查询条件
        $com_sms_where = array();
        if(!empty($phone))$com_sms_where["phone"] = array("like","%{$phone}%");

        //短信发送日志
        $com_sms_list = IDb::getInstance("com_sms")->setDbWhere($com_sms_where)->setDbOrder("sms_id desc")->pag();

        //模板渲染
        $this->assign('phone',$phone);
        $this->assign('com_sms_list',$com_sms_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：意见反馈日志
     * @开发者：cxl
     */
    public function suggest_list(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $agent_admin_id = IRequest::get("agent_admin_id");
        $cooperate_admin_id = IRequest::get("cooperate_admin_id");
        $admin_id = IRequest::get("admin_id");

        //查询条件
        $suggest_where = "suggest_id in (select max(suggest_id) from ".get_table("com_suggest")." group by user_id,agent_admin_id,cooperate_admin_id order by create_time desc)";
        if(!empty($user_id))$suggest_where .= " and user_id='{$user_id}'";
        if(!empty($agent_admin_id))$suggest_where .= " and agent_admin_id='{$agent_admin_id}'";
        if(!empty($cooperate_admin_id))$suggest_where .= " and cooperate_admin_id='{$cooperate_admin_id}'";
        if(!empty($admin_id))$suggest_where .= " and admin_id='{$admin_id}'";

        //取得数量
        $suggest_count = IDb::getInstance("com_suggest")->setDbWhere($suggest_where)->con();

        //意见反馈日志
        $suggest_list = IDb::getInstance("com_suggest")->setDbWhere($suggest_where)->setDbOrder("suggest_type,create_time desc")->pag(20,$suggest_count);

        //模板渲染
        $this->assign('user_id',$user_id);
        $this->assign('agent_admin_id',$agent_admin_id);
        $this->assign('cooperate_admin_id',$cooperate_admin_id);
        $this->assign('suggest_list',$suggest_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：意见反馈回复
     * @开发者：cxl
     */
    public function suggest_send(){
        //接收参数
        $user_id = IRequest::get('user_id',IRequest::NOT_EMPTY,"客户编号不能为空！");

        //模板渲染
        $this->assign('user_id',$user_id);

        //渲染模板输出
        return view();
    }
    /**
     * @功能：意见反馈回复
     * @开发者：cxl
     */
    public function suggest_agent_send(){
        //接收参数
        $agent_admin_id = IRequest::get('agent_admin_id',IRequest::NOT_EMPTY,"客户编号不能为空！");

        //模板渲染
        $this->assign('agent_admin_id',$agent_admin_id);

        //渲染模板输出
        return view();
    }
    /**
     * @功能：意见反馈回复
     * @开发者：cxl
     */
    public function suggest_cooperate_send(){
        //接收参数
        $cooperate_admin_id = IRequest::get('cooperate_admin_id',IRequest::NOT_EMPTY,"客户编号不能为空！");

        //模板渲染
        $this->assign('cooperate_admin_id',$cooperate_admin_id);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：意见反馈回复提交
     * @开发者：cxl
     */
    public function suggest_submit(){
        //接收参数
        $user_id = IRequest::get('user_id',IRequest::NOT_EMPTY,"客户编号不能为空！");
        $content  = IRequest::get('content',IRequest::NOT_EMPTY,"意见反馈内容不能为空！");

        //添加意见反馈
        if(!empty($user_id)) $suggest_data['user_id'] = $user_id;
        $suggest_data['suggest_type'] = SuggestType::Admin;
        $suggest_data['admin_id'] = get_login_admin_id();
        $suggest_data['content'] = $content;
        $suggest_add = IDb::getInstance("com_suggest")->setDbData($suggest_data)->add();
        if($suggest_add === false){
            error("意见反馈回复失败！");
        }

        //画面跳转
        $this->redirect("suggest_list");
    }

    /**
     * @功能：意见反馈回复提交
     * @开发者：cxl
     */
    public function suggest_agent_submit(){
        //接收参数
        $agent_admin_id = IRequest::get('agent_admin_id',IRequest::NOT_EMPTY,"信贷经理编号不能为空！");
        $content  = IRequest::get('content',IRequest::NOT_EMPTY,"意见反馈内容不能为空！");

        //添加意见反馈
        if(!empty($agent_admin_id)) $suggest_data['agent_admin_id'] = $agent_admin_id;
        $suggest_data['suggest_type'] = SuggestType::Admin;
        $suggest_data['admin_id'] = get_login_admin_id();
        $suggest_data['content'] = $content;
        $suggest_add = IDb::getInstance("com_suggest")->setDbData($suggest_data)->add();
        if($suggest_add === false){
            error("意见反馈回复失败！");
        }

        //画面跳转
        $this->redirect("suggest_list");
    }

    /**
     * @功能：意见反馈回复提交
     * @开发者：cxl
     */
    public function suggest_cooperate_submit(){
        //接收参数
        $cooperate_admin_id = IRequest::get('cooperate_admin_id',IRequest::NOT_EMPTY,"合作商编号不能为空！");
        $content  = IRequest::get('content',IRequest::NOT_EMPTY,"意见反馈内容不能为空！");

        //添加意见反馈
        if(!empty($cooperate_admin_id)) $suggest_data['cooperate_admin_id'] = $cooperate_admin_id;
        $suggest_data['suggest_type'] = SuggestType::Admin;
        $suggest_data['admin_id'] = get_login_admin_id();
        $suggest_data['content'] = $content;
        $suggest_add = IDb::getInstance("com_suggest")->setDbData($suggest_data)->add();
        if($suggest_add === false){
            error("意见反馈回复失败！");
        }

        //画面跳转
        $this->redirect("suggest_list");
    }

    /**
     * @功能：意见反馈详情
     * @开发者：cxl
     */
    public function suggest_info(){
        //接收参数
        $user_id = IRequest::get('user_id',IRequest::NOT_EMPTY,"客户编号不能为空！");

        //取得管理员角色数据
        $suggest_where = null;
        if(!empty($user_id)) $suggest_where['user_id'] = $user_id;
        $suggest_list = IDb::getInstance("com_suggest")->setDbWhere($suggest_where)->setDbOrder("create_time desc")->pag();

        //模板渲染
        $this->layout("layout_empty");
        $this->assign('suggest_list',$suggest_list);

        //渲染模板输出
        return view();
    }
    /**
     * @功能：意见反馈详情
     * @开发者：cxl
     */
    public function suggest_agent_info(){
        //接收参数
        $agent_admin_id = IRequest::get('agent_admin_id',IRequest::NOT_EMPTY,"信贷经理编号不能为空！");

        //取得管理员角色数据
        $suggest_where = null;
        if(!empty($agent_admin_id)) $suggest_where['agent_admin_id'] = $agent_admin_id;
        $suggest_list = IDb::getInstance("com_suggest")->setDbWhere($suggest_where)->setDbOrder("create_time desc")->pag();

        //模板渲染
        $this->layout("layout_empty");
        $this->assign('suggest_list',$suggest_list);

        //渲染模板输出
        return view();
    }
    /**
     * @功能：意见反馈详情
     * @开发者：cxl
     */
    public function suggest_cooperate_info(){
        //接收参数
        $cooperate_admin_id = IRequest::get('cooperate_admin_id',IRequest::NOT_EMPTY,"合作商编号不能为空！");

        //取得管理员角色数据
        $suggest_where = null;
        if(!empty($cooperate_admin_id)) $suggest_where['cooperate_admin_id'] = $cooperate_admin_id;
        $suggest_list = IDb::getInstance("com_suggest")->setDbWhere($suggest_where)->setDbOrder("create_time desc")->pag();

        //模板渲染
        $this->layout("layout_empty");
        $this->assign('suggest_list',$suggest_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：行政区域列表
     * @开发者：cxl
     */
    public function area_list(){
        //接收参数
        $parent_id = IRequest::get("parent_id");

        //判断是否为空
        if(empty($parent_id)){
            $parent_id = 0;
        }

        //行政区域列表
        $area_list = IAreaCache::getList($parent_id);
        if($area_list === false){
            error("取得行政区域列表失败！");
        }

        //模板渲染
        $this->assign('area_list',$area_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：添加行政区域
     * @开发者：cxl
     */
    public function area_add(){
        //接收参数
        $parent_id = IRequest::get("area_id",IRequest::NOT_EMPTY,"上层行政区域编号不能为空！");

        //模板渲染
        $this->assign('parent_id',$parent_id);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑行政区域
     * @开发者：cxl
     */
    public function area_edit(){
        //接收参数
        $area_id = IRequest::get("area_id",IRequest::NOT_EMPTY,"上层行政区域编号不能为空！");

        //行政区域列表
        $area_info = IAreaCache::getInfo($area_id);
        if($area_info === false){
            error("取得行政区域详情失败！");
        }

        //模板渲染
        $this->assign('area_id',$area_id);
        $this->assign('area_info',$area_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：行政区域提交
     * @开发者：cxl
     */
    public function area_submit(){
        //接收参数
        $area_id = IRequest::get("area_id");
        $acronym = IRequest::get("acronym",IRequest::NOT_EMPTY,"行政区域简称不能为空！");
        $area_name = IRequest::get("area_name",IRequest::NOT_EMPTY,"行政区域名称不能为空！");
        $order_by = IRequest::get("order_by");

        //判断操作类型
        if(empty($area_id)) {
            //接收参数
            $parent_id = IRequest::get("parent_id",IRequest::NOT_EMPTY,"上层行政区域编号不能为空！");

            //取得上层节点信息
            $area_info = IAreaCache::getInfo($parent_id);
            if (empty($area_info['area_type'])) {
                error("增加行政区域失败！");
            }

            //行政区域列表
            $area_data["area_type"] = $area_info['area_type'];
            $area_data["parent_id"] = $parent_id;
            $area_data["acronym"] = $acronym;
            $area_data["area_name"] = $area_name;
            $area_data["order_by"] = $order_by;
            $area_id = IDb::getInstance("com_area")->setDbData($area_data)->add();
            if ($area_id === false) {
                error("增加行政区域失败！");
            }
        }else{
            //取得上层节点编号
            $area_info = IAreaCache::getInfo($area_id);
            if(empty($area_info)){
                error("增加行政区域失败！");
            }

            //行政区域列表
            $parent_id = $area_info['area_id'];
            $area_data["acronym"] = $acronym;
            $area_data["area_name"] = $area_name;
            $area_data["order_by"] = $order_by;
            $area_where['area_id'] = array("eq",$area_id);
            $area_upd = IDb::getInstance("com_area")->setDbWhere($area_where)->setDbData($area_data)->upd();
            if ($area_upd === false) {
                error("修改行政区域失败！");
            }
        }

        //清除缓存
        IAreaCache::deleteList($parent_id);
        IAreaCache::deleteInfo($area_id);
        IAreaCache::deleteAllList(1);
        IAreaCache::deleteAllList(2);
        IAreaCache::deleteAllList(3);
        IAreaCache::deleteLocation();
        IAreaCache::deleteLocationIndex();

        //画面跳转
        $this->redirect("area_list");
    }

    /**
     * @功能：删除行政区域
     * @开发者：cxl
     */
    public function area_del(){
        //接收参数
        $area_id = IRequest::get("area_id",IRequest::NOT_EMPTY,"上层行政区域编号不能为空！");

        //行政区域列表
        $area_data["is_delete"] = IsDelete::Yes;
        $area_where['area_id'] = $area_id;
        $area_upd = IDb::getInstance("com_area")->setDbWhere($area_where)->setDbData($area_data)->upd();
        if ($area_upd === false) {
            error("删除行政区域失败！");
        }

        //取得上层节点编号
        $area_info = IAreaCache::getInfo($area_id);
        if(empty($area_info)){
            error("增加行政区域失败！");
        }

        //清除缓存
        IAreaCache::deleteList($area_info['area_id']);
        IAreaCache::deleteInfo($area_id);
        IAreaCache::deleteAllList(1);
        IAreaCache::deleteAllList(2);
        IAreaCache::deleteAllList(3);
        IAreaCache::deleteLocation();
        IAreaCache::deleteLocationIndex();

        //画面跳转
        $this->redirect("area_list");
    }

    /**
     * @功能：行政区域还原
     * @开发者：cxl
     */
    public function area_reset(){
        //接收参数
        $area_id = IRequest::get("area_id",IRequest::NOT_EMPTY,"上层行政区域编号不能为空！");

        //行政区域列表
        $area_data["is_delete"] = IsDelete::No;
        $area_where['area_id'] = array("eq",$area_id);
        $area_upd = IDb::getInstance("com_area")->setDbWhere($area_where)->setDbData($area_data)->add();
        if ($area_upd === false) {
            error("还原行政区域失败！");
        }

        //取得上层节点编号
        $area_info = IAreaCache::getInfo($area_id);
        if(empty($area_info)){
            error("增加行政区域失败！");
        }

        //清除缓存
        IAreaCache::deleteList($area_info['area_id']);
        IAreaCache::deleteInfo($area_id);
        IAreaCache::deleteAllList(1);
        IAreaCache::deleteAllList(2);
        IAreaCache::deleteAllList(3);
        IAreaCache::deleteLocation();
        IAreaCache::deleteLocationIndex();

        //画面跳转
        $this->redirect("area_list");
    }

    /**
     * @功能：广告位列表
     * @开发者：cxl
     */
    public function ad_location_list(){
        //接收参数
        $app_type = IRequest::get("app_type");

        //获取广告位列表
        $ad_location_where = null;
        if(!empty($app_type))$ad_location_where['app_type'] = $app_type;
        $ad_location_list = IDb::getInstance("com_ad_location")->setDbWhere($ad_location_where)->sel();

        //模板渲染
        $this->assign('app_type',$app_type);
        $this->assign('ad_location_list',$ad_location_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告位添加
     * @开发者：cxl
     */
    public function ad_location_add(){
        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告位编辑
     * @开发者：cxl
     */
    public function ad_location_edit(){
        //接收参数
        $ad_location_id = IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");

        //实例化对象
        $ad_location_info = IAdLocationCache::getInfo($ad_location_id);

        //模板渲染
        $this->assign('ad_location_id',$ad_location_id);
        $this->assign('ad_location_info',$ad_location_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告位编辑提交
     * @开发者：cxl
     */
    public function ad_location_submit(){
        //接收参数
        $ad_location_id = IRequest::get("ad_location_id");
        $app_type = IRequest::get("app_type",IRequest::NOT_EMPTY,"APP类型不能为空！");
        $ad_location_name = IRequest::get("ad_location_name",IRequest::NOT_EMPTY,"广告位名称不能为空！");
        $ad_location_type = IRequest::get("ad_location_type",IRequest::NOT_EMPTY,"广告位类型不能为空！");
        $number = IRequest::get("number",IRequest::NOT_EMPTY,"广告数量不能为空！");
        $width = IRequest::get("width",IRequest::NOT_EMPTY,"广告宽度不能为空！");
        $height = IRequest::get("height",IRequest::NOT_EMPTY,"广告高度不能为空！");

        //判断是修改还是添加
        if(empty($ad_location_id)) {
            //接收参数
            $ad_location_code = IRequest::get("ad_location_code",IRequest::NOT_EMPTY,"广告位编码不能为空！");

            //实例化对象
            $ad_location_where['ad_location_code'] = $ad_location_code;
            $ad_location_exist = IDb::getInstance("com_ad_location")->setDbWhere($ad_location_where)->row();
            if(!empty($ad_location_exist)){
                error('广告位编码不可重复');
            }

            //添加广告位编号
            $ad_location_data = null;
            $ad_location_where = null;
            $ad_location_data['app_type'] = $app_type;
            $ad_location_data['ad_location_name'] = $ad_location_name;
            $ad_location_data['ad_location_type'] = $ad_location_type;
            $ad_location_data['ad_location_code'] = $ad_location_code;
            $ad_location_data['number'] = $number;
            $ad_location_data['width'] = $width;
            $ad_location_data['height'] = $height;
            $ad_location_add = IDb::getInstance("com_ad_location")->setDbData($ad_location_data)->add();
            if($ad_location_add === false){
                error('添加失败');
            }
        }else{
            //实例化对象
            $ad_location_where['ad_location_id'] = array("neq",$ad_location_id);
            $ad_location_info = IDb::getInstance("com_ad_location")->setDbWhere($ad_location_where)->row();
            if($ad_location_info === false){
                error('广告位编码不可重复');
            }

            //修改广告位
            $ad_location_data = null;
            $ad_location_where = null;
            $ad_location_data['app_type'] = $app_type;
            $ad_location_data['ad_location_name'] = $ad_location_name;
            $ad_location_data['ad_location_type'] = $ad_location_type;
            $ad_location_data['number'] = $number;
            $ad_location_data['width'] = $width;
            $ad_location_data['height'] = $height;
            $ad_location_where['ad_location_id'] = array("eq",$ad_location_id);
            $ad_location_upd = IDb::getInstance("com_ad_location")->setDbWhere($ad_location_where)->setDbData($ad_location_data)->upd();
            if($ad_location_upd === false){
                error('修改失败！');
            }

            //清除缓存
            IAdLocationCache::deleteInfo($ad_location_id);
        }

        //清除缓存
        IAdLocationCache::deleteList(AppType::YH);
        IAdLocationCache::deleteList(AppType::XD);

        //画面跳转
        $this->success('操作成功',Url('ad_location_list'));
    }

    /**
     * @功能：广告列表
     * @开发者：cxl
     */
    public function ad_list(){
        //接收参数
        $ad_location_id= IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");

        //实例化对象
        $ad_location_info = IAdLocationCache::getInfo($ad_location_id);
        if(empty($ad_location_info)){
            error('广告位不存在');
        }

        //获取广告位列表
        $ad_where['ad_location_id'] = $ad_location_id;
        $ad_list = IDb::getInstance("com_ad")->setDbWhere($ad_where)->sel();

        //模板渲染
        $this->assign('ad_location_id',$ad_location_id);
        $this->assign('ad_location_info',$ad_location_info);
        $this->assign('ad_list',$ad_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告添加
     * @开发者：cxl
     */
    public function ad_add(){
        //接收参数
        $ad_location_id= IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

        //模板渲染
        $this->assign('area_list',$area_list);
        $this->assign('ad_location_id',$ad_location_id);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告编辑
     * @开发者：cxl
     */
    public function ad_edit(){
        //接收参数
        $ad_id = IRequest::get("ad_id",IRequest::NOT_EMPTY,"广告编号不能为空！");

        //实例化对象
        $ad_where['ad_id'] = $ad_id;
        $ad_info = IDb::getInstance("com_ad")->setDbWhere($ad_where)->row();

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(2);

        //设置区域信息
        $area[] = $ad_info['province_id'];
        $area[] = $ad_info['city_id'];

        //模板渲染
        $this->assign('ad_id',$ad_id);
        $this->assign('area_list',$area_list);
        $this->assign('area',$area);
        $this->assign('ad_info',$ad_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：广告编辑提交
     * @开发者：cxl
     */
    public function ad_submit(){
        //接收参数
        $ad_id = IRequest::get("ad_id");
        $ad_location_id = IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");
        $ad_name = IRequest::get("ad_name",IRequest::NOT_EMPTY,"广告名称不能为空！");
        $ad_photo_url = IRequest::get("ad_photo_url",IRequest::NOT_EMPTY,"广告图片不能为空！");
        $area = IRequest::get("area");
        $ad_goto_url = IRequest::get("ad_goto_url");
        $order_by = IRequest::get("order_by");
        $remark = IRequest::get("remark");

        //整理区域数据
        $province_id = null;
        $city_id = null;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0]; //取得省份
            if(!empty($area[1])) $city_id = $area[1]; //取得城市
        }

        //判断是修改还是添加
        if(empty($ad_id)) {
            //添加广告位编号
            $ad_data['ad_location_id'] = $ad_location_id;
            $ad_data['province_id'] = $province_id;
            $ad_data['city_id'] = $city_id;
            $ad_data['ad_name'] = $ad_name;
            $ad_data['ad_photo_url'] = $ad_photo_url;
            $ad_data['ad_goto_url'] = $ad_goto_url;
            $ad_data['order_by'] = $order_by;
            $ad_data['remark'] = $remark;
            $ad_data['create_admin'] = get_login_admin_id();
            $ad_data['create_time'] = get_date_time();
            $ad_add = IDb::getInstance("com_ad")->setDbData($ad_data)->add();
            if($ad_add === false){
                error('添加失败');
            }
        }else{
            //修改广告位
            $ad_data['ad_location_id'] = $ad_location_id;
            $ad_data['province_id'] = $province_id;
            $ad_data['city_id'] = $city_id;
            $ad_data['ad_name'] = $ad_name;
            $ad_data['ad_photo_url'] = $ad_photo_url;
            $ad_data['ad_goto_url'] = $ad_goto_url;
            $ad_data['order_by'] = $order_by;
            $ad_data['remark'] = $remark;
            $ad_data['update_admin'] = get_login_admin_id();
            $ad_data['update_time'] = get_date_time();
            $ad_where['ad_id'] = array("eq",$ad_id);
            $ad_where['ad_location_id'] = array("eq",$ad_location_id);
            $ad_upd = IDb::getInstance("com_ad")->setDbWhere($ad_where)->setDbData($ad_data)->upd();
            if($ad_upd === false){
                error('修改失败！');
            }
        }

        //清除广告缓存信息
        IAdCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('ad_list',array("ad_location_id"=>$ad_location_id)));
    }

    /**
     * @功能：删除广告
     * @开发者：cxl
     */
    public function ad_del(){
        //接收参数
        $ad_location_id= IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");
        $ad_id = IRequest::get("ad_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得广告信息
        $ad_where['ad_location_id'] = array("eq",$ad_location_id);
        $ad_where['ad_id'] = array("eq",$ad_id);
        $ad_info = IDb::getInstance("com_ad")->setDbWhere($ad_where)->row();
        if ($ad_info === false) {
            error("删除广告失败！");
        }

        //区域列表
        $ad_data["is_delete"] = IsDelete::Yes;
        $ad_upd = IDb::getInstance("com_ad")->setDbWhere($ad_where)->setDbData($ad_data)->upd();
        if ($ad_upd === false) {
            error("删除广告失败！");
        }

        //清除广告缓存信息
        IAdCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('ad_list',array("ad_location_id"=>$ad_location_id)));
    }

    /**
     * @功能：还原广告
     * @开发者：cxl
     */
    public function ad_reset(){
        //接收参数
        $ad_location_id= IRequest::get("ad_location_id",IRequest::NOT_EMPTY,"广告位编号不能为空！");
        $ad_id = IRequest::get("ad_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得广告信息
        $ad_where['ad_location_id'] = array("eq",$ad_location_id);
        $ad_where['ad_id'] = array("eq",$ad_id);
        $ad_info = IDb::getInstance("com_ad")->setDbWhere($ad_where)->row();
        if ($ad_info === false) {
            error("删除广告失败！");
        }

        //区域列表
        $ad_data["is_delete"] = IsDelete::No;
        $ad_where['ad_location_id'] = array("eq",$ad_location_id);
        $ad_where['ad_id'] = array("eq",$ad_id);
        $ad_upd = IDb::getInstance("com_ad")->setDbWhere($ad_where)->setDbData($ad_data)->upd();
        if ($ad_upd === false) {
            error("还原广告失败！");
        }

        //清除广告缓存信息
        IAdCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('ad_list',array("ad_location_id"=>$ad_location_id)));
    }

    /**
     * @功能：协议列表
     * @开发者：cxl
     */
    public function protocol_list(){
        //实例化对象
        $protocol_list = IDb::getInstance("com_protocol")->sel();

        //模板渲染
        $this->assign('protocol_list',$protocol_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：协议详情
     * @开发者：cxl
     */
    public function protocol_info(){
        //接收参数
        $protocol_code = IRequest::get("protocol_code",IRequest::NOT_EMPTY,"协议编码不能为空！");

        //实例化对象
        $protocol_info = IProtocolCache::getInfo($protocol_code);

        //模板渲染
        $this->assign('protocol_info',$protocol_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：编辑协议
     * @开发者：cxl
     */
    public function protocol_edit(){
        //接收参数
        $protocol_code = IRequest::get("protocol_code",IRequest::NOT_EMPTY,"协议编码不能为空！");

        //实例化对象
        $protocol_info = IProtocolCache::getInfo($protocol_code);

        //模板渲染
        $this->assign('protocol_code',$protocol_code);
        $this->assign('protocol_info',$protocol_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：协议编辑提交
     * @开发者：cxl
     */
    public function protocol_submit(){
        //接收参数
        $protocol_id = IRequest::get("protocol_id",IRequest::NOT_EMPTY,"协议编号不能为空！");
        $protocol_code = IRequest::get("protocol_code",IRequest::NOT_EMPTY,"协议编码不能为空！");
        $protocol_title = IRequest::get("protocol_title",IRequest::NOT_EMPTY,"协议标题不能为空！");
        $protocol_content = IRequest::get("protocol_content",IRequest::NOT_EMPTY,"协议内容不能为空！");

        //修改广告位
        $protocol_data['protocol_title'] = $protocol_title;
        $protocol_data['protocol_content'] = $protocol_content;
        $protocol_data['update_admin'] = get_login_admin_id();
        $protocol_data['update_time'] = get_date_time();
        $protocol_where['protocol_id'] = array("eq",$protocol_id);
        $protocol_where['protocol_code'] = array("eq",$protocol_code);
        $protocol_upd = IDb::getInstance("com_protocol")->setDbWhere($protocol_where)->setDbData($protocol_data)->upd();
        if($protocol_upd === false){
            error('修改失败！');
        }

        //清除缓存
        IProtocolCache::deleteInfo($protocol_code);

        //画面跳转
        $this->success('操作成功');
    }

    /**
     * @功能：待回答列表
     * @开发者：cxl
     * @return string
     */
    public function question_wait_list(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $loan_agency_id = IRequest::get("loan_agency_id");
        $reply_admin_id = IRequest::get("reply_admin_id");
        $reply_agent_admin_id = IRequest::get("reply_agent_admin_id");
        $question_content = IRequest::get('question_content');
        $question_type = IRequest::get('question_type');

        //取得数据
        $where['reply_content'] = array("exp"," is null");
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($loan_agency_id)) $where['loan_agency_id'] = $loan_agency_id;
        if(!empty($reply_admin_id)) $where['reply_admin_id'] = $reply_admin_id;
        if(!empty($reply_agent_admin_id)) $where['reply_agent_admin_id'] = $reply_agent_admin_id;
        if(!empty($question_content)) $where['question_content'] = ['like','%'.$question_content.'%'];
        if(!empty($question_type)) $where['question_type'] = $question_type;
        $question_list = IDb::getInstance("question")
            ->setDbWhere($where)
            ->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("loan_agency_id",$loan_agency_id);
        $this->assign("reply_admin_id",$reply_admin_id);
        $this->assign("reply_agent_admin_id",$reply_agent_admin_id);
        $this->assign("question_list",$question_list);
        $this->assign("question_content",$question_content);
        $this->assign("question_type",$question_type);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：已问答列表
     * @开发者：cxl
     * @return string
     */
    public function question_list(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $loan_agency_id = IRequest::get("loan_agency_id");
        $reply_admin_id = IRequest::get("reply_admin_id");
        $reply_agent_admin_id = IRequest::get("reply_agent_admin_id");
        $question_content = IRequest::get('question_content');
        $question_type = IRequest::get('question_type');

        //取得数据
        $where['reply_content'] = array("exp"," is not null");
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($loan_agency_id)) $where['loan_agency_id'] = $loan_agency_id;
        if(!empty($reply_admin_id)) $where['reply_admin_id'] = $reply_admin_id;
        if(!empty($reply_agent_admin_id)) $where['reply_agent_admin_id'] = $reply_agent_admin_id;
        if(!empty($question_content)) $where['question_content'] = ['like','%'.$question_content.'%'];
        if(!empty($question_type)) $where['question_type'] = $question_type;
        $question_list = IDb::getInstance("question")
            ->setDbWhere($where)
            ->setDbOrder("question_id desc")
            ->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("loan_agency_id",$loan_agency_id);
        $this->assign("reply_admin_id",$reply_admin_id);
        $this->assign("reply_agent_admin_id",$reply_agent_admin_id);
        $this->assign("question_list",$question_list);
        $this->assign("question_content",$question_content);
        $this->assign("question_type",$question_type);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：问答详情
     * @开发者：cxl
     * @return string
     */
    public function question_info(){
        //接收参数
        $question_id = IRequest::get("question_id",IRequest::NOT_EMPTY,"问答编号不能为空！");

        //取得数据
        $where['question_id'] = $question_id;
        $question_info = IDb::getInstance("question")->setDbWhere($where)->row();

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("question_info",$question_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：问答
     * @开发者：cxl
     * @return string
     */
    public function question_reply(){
        //接收参数
        $question_id = IRequest::get("question_id",IRequest::NOT_EMPTY,"问答编号不能为空！");

        //取得数据
        $where['question_id'] = $question_id;
        $question_info = IDb::getInstance("question")->setDbWhere($where)->row();

        //页面赋值
        $this->assign("question_id",$question_id);
        $this->assign("question_info",$question_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：问答
     * @开发者：cxl
     * @return string
     */
    public function question_reply_submit(){
        //接收参数
        $question_id = IRequest::get("question_id",IRequest::NOT_EMPTY,"问答编号不能为空！");
        $reply_content = IRequest::get("reply_content",IRequest::NOT_EMPTY,"答复内容不能为空！");
        $seo_keywords = IRequest::get("seo_keywords");
        $seo_description = IRequest::get("seo_description");

        //取得数据
        $where['question_id'] = $question_id;
        $data['reply_admin_id'] = get_login_admin_id();
        $data['reply_content'] = $reply_content;
        $data['reply_time'] = get_date_time();
        $data['seo_keywords'] = $seo_keywords;
        $data['seo_description'] = $seo_description;
        $question_upd = IDb::getInstance("question")->setDbData($data)->setDbWhere($where)->upd();
        if($question_upd === false){
            error("答复失败！");
        }

        //画面跳转
        $this->success("操作成功！",Url("question_wait_list"));
    }

    /**
     * @功能：首页导航菜单列表
     * @开发者：cxl
     */
    public function navigation_list(){
        //实例化对象
        $navigation_list = IDb::getInstance('com_navigation')->setDbOrder("order_by desc,navigation_id desc")->sel();

        //模板渲染
        $this->assign('navigation_list',$navigation_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：首页导航菜单添加
     * @开发者：cxl
     */
    public function navigation_add(){
        return view();
    }

    /**
     * @功能：首页导航菜单编辑
     * @开发者：cxl
     */
    public function navigation_edit(){
        //接收参数
        $navigation_id = IRequest::get("navigation_id",IRequest::NOT_EMPTY,"首页导航菜单编号不能为空！");

        //实例化对象
        $navigation_where['navigation_id'] = $navigation_id;
        $navigation_info = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->row();

        //模板渲染
        $this->assign('navigation_id',$navigation_id);
        $this->assign('navigation_info',$navigation_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：首页导航菜单编辑提交
     * @开发者：cxl
     */
    public function navigation_submit(){
        //接收参数
        $navigation_id = IRequest::get("navigation_id");
        $navigation_name = IRequest::get("navigation_name",IRequest::NOT_EMPTY,"首页导航菜单名称不能为空！");
        $navigation_photo_url = IRequest::get("navigation_photo_url",IRequest::NOT_EMPTY,"首页导航菜单图片不能为空！");
        $navigation_go_url = IRequest::get("navigation_go_url");
        $order_by = IRequest::get("order_by");
        $remark = IRequest::get("remark");

        //判断是修改还是添加
        if(empty($navigation_id)) {
            //添加首页导航菜单位编号
            $navigation_data['navigation_name'] = $navigation_name;
            $navigation_data['navigation_photo_url'] = $navigation_photo_url;
            $navigation_data['navigation_go_url'] = $navigation_go_url;
            $navigation_data['order_by'] = $order_by;
            $navigation_data['remark'] = $remark;
            $navigation_data['create_admin_id'] = get_login_admin_id();
            $navigation_data['create_time'] = get_date_time();
            $navigation_add = IDb::getInstance("com_navigation")->setDbData($navigation_data)->add();
            if($navigation_add === false){
                error('首页导航菜单添加失败');
            }
        }else{
            //修改首页导航菜单位
            $navigation_where['navigation_id'] = $navigation_id;
            $navigation_data['navigation_name'] = $navigation_name;
            $navigation_data['navigation_photo_url'] = $navigation_photo_url;
            $navigation_data['navigation_go_url'] = $navigation_go_url;
            $navigation_data['order_by'] = $order_by;
            $navigation_data['remark'] = $remark;
            $navigation_data['update_admin_id'] = get_login_admin_id();
            $navigation_data['update_time'] = get_date_time();
            $navigation_upd = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->setDbData($navigation_data)->upd();
            if($navigation_upd === false){
                error('首页导航菜单修改失败！');
            }
        }

        //清除首页导航菜单缓存信息
        INavigationCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('navigation_list'));
    }

    /**
     * @功能：删除首页导航菜单
     * @开发者：cxl
     */
    public function navigation_del(){
        //接收参数
        $navigation_id = IRequest::get("navigation_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得首页导航菜单信息
        $navigation_where['navigation_id'] = $navigation_id;
        $navigation_info = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->row();
        if ($navigation_info === false) {
            error("删除首页导航菜单失败！");
        }

        //行政区域列表
        $navigation_where['navigation_id'] = $navigation_id;
        $navigation_data["is_delete"] = IsDelete::Yes;
        $navigation_upd = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->setDbData($navigation_data)->upd();
        if ($navigation_upd === false) {
            error("删除首页导航菜单失败！");
        }

        //清除首页导航菜单缓存信息
        INavigationCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('navigation_list'));
    }

    /**
     * @功能：还原首页导航菜单
     * @开发者：cxl
     */
    public function navigation_reset(){
        //接收参数
        $navigation_id = IRequest::get("navigation_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得首页导航菜单信息
        $navigation_where['navigation_id'] = $navigation_id;
        $navigation_info = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->row();
        if ($navigation_info === false) {
            error("删除首页导航菜单失败！");
        }

        //行政区域列表
        $navigation_where['navigation_id'] = $navigation_id;
        $navigation_data["is_delete"] = IsDelete::No;
        $navigation_upd = IDb::getInstance("com_navigation")->setDbWhere($navigation_where)->setDbData($navigation_data)->upd();
        if ($navigation_upd === false) {
            error("删除首页导航菜单失败！");
        }

        //清除首页导航菜单缓存信息
        INavigationCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('navigation_list'));
    }

    /**
     * @功能：专题列表
     * @开发者：cxl
     */
    public function special_list(){
        //实例化对象
        $special_list = IDb::getInstance('com_special')->setDbOrder("order_by desc,special_id desc")->sel();

        //模板渲染
        $this->assign('special_list',$special_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：专题添加
     * @开发者：cxl
     */
    public function special_add(){
        return view();
    }

    /**
     * @功能：专题编辑
     * @开发者：cxl
     */
    public function special_edit(){
        //接收参数
        $special_id = IRequest::get("special_id",IRequest::NOT_EMPTY,"专题编号不能为空！");

        //实例化对象
        $special_where['special_id'] = $special_id;
        $special_info = IDb::getInstance("com_special")->setDbWhere($special_where)->row();

        //模板渲染
        $this->assign('special_id',$special_id);
        $this->assign('special_info',$special_info);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：专题编辑提交
     * @开发者：cxl
     */
    public function special_submit(){
        //接收参数
        $special_id = IRequest::get("special_id");
        $special_name = IRequest::get("special_name",IRequest::NOT_EMPTY,"专题名称不能为空！");
        $special_photo_url = IRequest::get("special_photo_url",IRequest::NOT_EMPTY,"专题图片不能为空！");
        $special_go_url = IRequest::get("special_go_url");
        $order_by = IRequest::get("order_by");
        $remark = IRequest::get("remark");

        //判断是修改还是添加
        if(empty($special_id)) {
            //添加专题位编号
            $special_data['special_name'] = $special_name;
            $special_data['special_photo_url'] = $special_photo_url;
            $special_data['special_go_url'] = $special_go_url;
            $special_data['order_by'] = $order_by;
            $special_data['remark'] = $remark;
            $special_data['create_admin_id'] = get_login_admin_id();
            $special_data['create_time'] = get_date_time();
            $special_add = IDb::getInstance("com_special")->setDbData($special_data)->add();
            if($special_add === false){
                error('专题添加失败');
            }
        }else{
            //修改专题位
            $special_where['special_id'] = $special_id;
            $special_data['special_name'] = $special_name;
            $special_data['special_photo_url'] = $special_photo_url;
            $special_data['special_go_url'] = $special_go_url;
            $special_data['order_by'] = $order_by;
            $special_data['remark'] = $remark;
            $special_data['update_admin_id'] = get_login_admin_id();
            $special_data['update_time'] = get_date_time();
            $special_upd = IDb::getInstance("com_special")->setDbWhere($special_where)->setDbData($special_data)->upd();
            if($special_upd === false){
                error('专题修改失败！');
            }
        }

        //清除专题缓存信息
        ISpecialCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('special_list'));
    }

    /**
     * @功能：删除专题
     * @开发者：cxl
     */
    public function special_del(){
        //接收参数
        $special_id = IRequest::get("special_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得专题信息
        $special_where['special_id'] = $special_id;
        $special_info = IDb::getInstance("com_special")->setDbWhere($special_where)->row();
        if ($special_info === false) {
            error("删除专题失败！");
        }

        //行政区域列表
        $special_where['special_id'] = $special_id;
        $special_data["is_delete"] = IsDelete::Yes;
        $special_upd = IDb::getInstance("com_special")->setDbWhere($special_where)->setDbData($special_data)->upd();
        if ($special_upd === false) {
            error("删除专题失败！");
        }

        //清除专题缓存信息
        ISpecialCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('special_list'));
    }

    /**
     * @功能：还原专题
     * @开发者：cxl
     */
    public function special_reset(){
        //接收参数
        $special_id = IRequest::get("special_id",IRequest::NOT_EMPTY,"启动页编号不能为空！");

        //取得专题信息
        $special_where['special_id'] = $special_id;
        $special_info = IDb::getInstance("com_special")->setDbWhere($special_where)->row();
        if ($special_info === false) {
            error("删除专题失败！");
        }

        //行政区域列表
        $special_where['special_id'] = $special_id;
        $special_data["is_delete"] = IsDelete::No;
        $special_upd = IDb::getInstance("com_special")->setDbWhere($special_where)->setDbData($special_data)->upd();
        if ($special_upd === false) {
            error("删除专题失败！");
        }

        //清除专题缓存信息
        ISpecialCache::deleteList();

        //画面跳转
        $this->success('操作成功',Url('special_list'));
    }

    /**
     * @功能：获取部门列表
     * @开发者：yy
     */
    public function department_list(){
        //接收参数
        $admin_department_id = IRequest::get('admin_department_id');

        //获取部门信息
        $admin_department_where = null;
        $admin_department_where['parent_id'] = 0;
        if(!empty($admin_department_id)) $admin_department_where['admin_department_id'] = $admin_department_id;
        $select_department_list = IDb::getInstance('admin_department')->setDbWhere($admin_department_where)->sel();

        $department_list = IDb::getInstance('admin_department')->sel();
        if(empty($department_list)){
            error('获取公司组织结构失败！');
        }

        //数据的整理
        foreach ($department_list as &$val){
            //获取城市名称
            $val['province_id'] = IAreaCache::getInfo($val['province_id'], 'acronym');
            $val['city_id'] = IAreaCache::getInfo($val['city_id'], 'acronym');
            $val['area_id'] = IAreaCache::getInfo($val['area_id'], 'acronym');
            $val['liability_admin_id'] = IAdminCache::getInfo($val['liability_admin_id'], 'real_name');
        }

        //操作url
        $department_root = url('department_add', array('admin_department_id'=>0));
        $department_add = url('department_add', array('admin_department_id'=>'{admin_department_id}'));
        $department_edit = url('department_edit', array('admin_department_id'=>'{admin_department_id}'));
        $department_del = url('department_del', array('admin_department_id'=>'{admin_department_id}'));
        $department_info = url('department_info', array('admin_department_id'=>'{admin_department_id}'));
        $department_reset = url('department_reset', array('admin_department_id'=>'{admin_department_id}'));

        //配置树参数
        ListTree::set("node",null,"admin_department_id"); //节点字段名
        ListTree::set("node_root",null,array("公司组织架构","<a href='{$department_root}' class='blue' >添加公司</a>")); //根节点字段名
        ListTree::set("node_filed","admin_department_name",array("部门名称","30%")); //字段列表
        ListTree::set("node_filed","province_id",array("省","10%")); //字段列表
        ListTree::set("node_filed","city_id",array("市","10%")); //字段列表
        ListTree::set("node_filed","area_id",array("市","10%")); //字段列表
        ListTree::set("node_filed","liability_admin_id",array("负责人","10%")); //字段列表
        ListTree::set("node_filed",
            "_href_",array(
                "操作","20%",
                "
                <a href='{$department_add}' class='blue' >添加公司部门</a>
                <a href='{$department_edit}' class='blue'>编辑部门</a>
                <a href='{$department_del}' class='blue info'>删除</a>
                <a href='{$department_info}' class='blue'>详情</a>
                ",
                "<a href='{$department_reset}'><font color='red'>还原</font></a>"
            )
        );

        //参数的赋值
        $this->assign('admin_department_id', $admin_department_id);
        $this->assign('department_list', $department_list);
        $this->assign('select_department_list', $select_department_list);

        //页面显示
        return view();

    }

    /**
     * @功能：部门的添加
     * @开发者：yy
     */
    public function department_add(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id",IRequest::NUMBER,"系统菜单编号不正确！");

        //初期化变量
        $parent_id = 0;
        $admin_department_name = "部门";

        //获取城市列表
        $area_list = IAreaCache::getAllList(3);


        //判断是否为编辑
        $area = null;
        if(empty($admin_department_id)){
            $parent_id = 0;
            $admin_department_name = "公司组织架构";

        }else{
            //取得等级
            $admin_department_where["admin_department_id"] = $admin_department_id;
            $admin_department_info = IDb::getInstance("admin_department")->setDbWhere($admin_department_where)->row();
            if(empty($admin_department_info)){
                error("取得部门信息失败！");
            }else{
                $parent_id = $admin_department_id;
                $admin_department_name = $admin_department_info['admin_department_name'];
                $area = array($admin_department_info['province_id'], $admin_department_info['city_id'], $admin_department_info['area_id']);
            }
        }



        //模板渲染
        $this->assign('parent_id',$parent_id);
        $this->assign('area_list',$area_list);
        $this->assign('admin_department_name',$admin_department_name);
        $this->assign('area',$area);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：部门的编辑
     * @开发者：yy
     */
    public function department_edit(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id",IRequest::NUMBER,"部门编号不正确！");

        //获取部门信息
        $admin_department_where['admin_department_id'] = $admin_department_id;
        $admin_department_info = IDb::getInstance('admin_department')->setDbWhere($admin_department_where)->row();

        //判断数据是否为空
        if(empty($admin_department_info)){
            error('获取部门信息有误！');
        }

        //获取城市列表
        $area_list = IAreaCache::getAllList(3);
        $area = array($admin_department_info['province_id'], $admin_department_info['city_id'], $admin_department_info['area_id']);

       //获取负责人信息
        $admin_list = IDb::getInstance('admin')->setDbFiled('admin_id,real_name')->sel();

        //模板渲染
        $this->assign('admin_department_info',$admin_department_info);
        $this->assign('area_list',$area_list);
        $this->assign('area',$area);
        $this->assign('admin_list',$admin_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：部门数据的提交
     * @开发者：yy
     */
    public function department_submit(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id");
        $admin_department_name = IRequest::get('admin_department_name', IRequest::NOT_EMPTY, '部门名称不能为空');
        $address = IRequest::get('address');
        $parent_id = IRequest::get('parent_id',IRequest::NOT_EMPTY, '父级部门id不能为空');
        $remark = IRequest::get('remark');
        $area = IRequest::get("area");

        //地址条件的处理
        $province_id = null;
        $city_id = null;
        $area_id = null;
        if(!empty($area) && $parent_id == 0){
            $province_id = $area[0];
            $city_id = $area[1];
            $area_id = $area[2];
        }

        //判断是增加，修改数据
        if(empty($admin_department_id)){
            //数据的增加
            $admin_department_data['admin_department_name'] = $admin_department_name;
            $admin_department_data['parent_id'] = $parent_id;
            $admin_department_data['remark'] = $remark;
            $admin_department_data['create_admin_id'] = get_login_admin_id();
            $admin_department_data['create_time'] = get_date_time();
            $admin_department_data['is_delete'] = IsDelete::No;

            //判断是否是添加公司
            if($parent_id == 0){
                $admin_department_data['province_id'] = $province_id;
                $admin_department_data['city_id'] = $city_id;
                $admin_department_data['area_id'] = $area_id;
                $admin_department_data['address'] = $address;
            }

            $admin_department_add = IDb::getInstance('admin_department')->setDbData($admin_department_data)->add();
            if($admin_department_add === false){
                error('部门添加失败！');
            }

        }else{
            //接收参数
            $liability_admin_id = IRequest::get('liability_admin_id',IRequest::NOT_EMPTY, '负责人编号不能为空');

            //数据的修改
            $admin_department_where['admin_department_id'] = $admin_department_id;
            $admin_department_data['admin_department_name'] = $admin_department_name;
            $admin_department_data['liability_admin_id'] = $liability_admin_id;
            $admin_department_data['remark'] = $remark;
            $admin_department_data['update_admin_id'] = get_login_admin_id();
            $admin_department_data['update_time'] = get_date_time();
            $admin_department_data['is_delete'] = IsDelete::No;

            //判断是否是修改公司
            if($parent_id == 0){
                $admin_department_data['province_id'] = $province_id;
                $admin_department_data['city_id'] = $city_id;
                $admin_department_data['area_id'] = $area_id;
                $admin_department_data['address'] = $address;
            }
            $admin_department_add = IDb::getInstance('admin_department')->setDbWhere($admin_department_where)->setDbData($admin_department_data)->upd();
            if($admin_department_add === false){
                error('部门修改失败！');
            }
        }

        //充值密码
        $this->success('操作成功！',Url("department_list"));
    }

    /**
     * @功能：部门的删除
     * @开发者：yy
     */
    public function department_del(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id",IRequest::NUMBER,"部门编号不正确！");

        //获取部门信息
        $admin_department_where['admin_department_id'] = $admin_department_id;
        $admin_department_data['is_delete'] = IsDelete::Yes;
        $admin_department_update = IDb::getInstance('admin_department')->setDbData($admin_department_data)->setDbWhere($admin_department_where)->upd();
        if($admin_department_update === false){
            error('部门删除失败！');
        }

        //成功跳转
        $this->success('操作成功！',Url("department_list"));
    }

    /**
     * @功能：部门的还原
     * @开发者：yy
     */
    public function department_reset(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id",IRequest::NUMBER,"部门编号不正确！");

        //获取部门信息
        $admin_department_where['admin_department_id'] = $admin_department_id;
        $admin_department_data['is_delete'] = IsDelete::No;
        $admin_department_update = IDb::getInstance('admin_department')->setDbData($admin_department_data)->setDbWhere($admin_department_where)->upd();
        if($admin_department_update === false){
            error('部门还原失败！');
        }

        //成功跳转
        $this->success('操作成功！',Url("department_list"));
    }

    /**
     * @功能：部门详情
     * @开发者：yy
     */
    public function department_info(){
        //接收参数
        $admin_department_id = IRequest::get("admin_department_id",IRequest::NUMBER,"部门编号不正确！");

        //获取部门信息
        $admin_department_where['admin_department_id'] = $admin_department_id;
        $admin_department_info = IDb::getInstance('admin_department')->setDbWhere($admin_department_where)->row();
        if($admin_department_info === false){
            error('获取部门信息失败！');
        }

        //获取负责人信息
        $admin_list = IDb::getInstance('admin')->setDbFiled('admin_id,real_name')->sel();

        //页面赋值
        $this->assign('admin_department_info',$admin_department_info);
        $this->assign('admin_list',$admin_list);

        return view();
    }
}
